﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;

namespace ImportDataCore
{
    public partial class UCLog : DevExpress.XtraEditors.XtraUserControl
    {
        public UCLog()
        {
            InitializeComponent();
            this.memoLog.Properties.ReadOnly = true;
        }

        public void AddLog(StringBuilder stringBuilder)
        {
            this.memoLog.Text += stringBuilder.ToString();
            Application.DoEvents();
        }

        private void btnImport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (string.IsNullOrEmpty(this.memoLog.Text))
            {
                MessageBox.Show("日志为空");
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "txt文件|*.txt";
            dlg.FilterIndex = 0;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                StreamWriter writer = new StreamWriter(dlg.FileName);
                writer.WriteLine(this.memoLog.Text);

                writer.Dispose();
                writer = null;
            }
        }

        private void btnClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.memoLog.Text = string.Empty;
        }


        public void ClearLog()
        {
            this.memoLog.Text = string.Empty;
        }
    }
}
